﻿using MediatR;
using ProductionManagement.Application.Command.FeedingCommand;
using ProductionManagement.Infrstructre.lnterface;

namespace ProductionManagement.Application.CommandHandler.FeedingCommandHandler
{
    public class DelFeedProductCommandHandler : IRequestHandler<DelFeedProductCommand, int>
    {
        IFeedProductRepository fpRep;

        public DelFeedProductCommandHandler(IFeedProductRepository fpRep)
        {
            this.fpRep = fpRep;
        }

        public async Task<int> Handle(DelFeedProductCommand request, CancellationToken cancellationToken)
        {
            var list = (await fpRep.GetAll()).Where(c => request.FeedProductId.Contains(c.FeedProductId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelTime = DateTime.Now;
                await fpRep.UpdAsync(item);
            }
            return 1;

        }
    }
}
